<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户密码修改</title>
<script type="text/javascript">
    var path = window.document.location.href;
	var pathName = window.document.location.pathname;
	var hostPath = path.substring(0, path.indexOf(pathName));
	var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
	document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr'+'ipt>');
</script>
</head>
<body>
	<table align="left" boder="1" cellspacing="10">
		<tr align="center">
			<td id="td_loginName" align="center">当前用户：loginName</td>
			<td id="td_userName" align="center">[userName]</td>
		</tr>
		<tr align="center">
			<td align="right">旧密码：</td>
			<td align="left"><input type="password" id="oldPassword" name="oldPassword"></td>
		</tr>
		<tr align="center">
			<td align="right">新密码：</td>
			<td align="left"><input type="password" id="newPassword" name="newPassword"></td>
		</tr>
		<tr align="center">
			<td align="right">再次输入新密码：</td>
			<td align="left"><input type="password" id="newPassword2" name="newPassword2"></td>
		</tr>
		<tr align="center">
			<td><a href="javascript:submitPwd()" class="easyui-linkbutton" iconCls="icon-ok">提交</a></td>
			<td><a href="javascript:console()" class="easyui-linkbutton" iconCls="icon-undo">重置</a>
		</tr>
	</table>
	<script>
		var initd = {
			dg:$('#dg'),
			dataDicList:{'ORG':['orgId'],'1':['status']}//需加载的 DATADIC 字典名+作用的字段名
        };
        
        var loginName = "";

		function console(){
			$("#oldPassword").attr("value","");
			$("#newPassword").attr("value","");
			$("#newPassword2").attr("value","");
		}
		
		function submitPwd() {
			var oldPassword  = $("#oldPassword").val();
			var newPassword  = $("#newPassword").val();
			var newPassword2 = $("#newPassword2").val();

			if(jQuery.isEmptyObject(loginName)){
				$.messager.alert('警告','用户名不存在！');
			}

			if(oldPassword=="" || newPassword=="" || newPassword2==""){
				$.messager.alert('警告','要素请填写完整！');
			}else if(newPassword != newPassword2){
				$.messager.alert('警告','两次输入的新密码不一致，请检查！');
			}
			else{
				$.ajax({
					type : "POST",
					url : projectName+"/system/userinfo/"+loginName+"/modfiyPwd",						
					data : {
						'oldPassword' : oldPassword,
						'newPassword' : newPassword
					},
					dataType : "json",
					success : function(data) {
						if (!data.success) {
							alert(data.message);
							return;
						}
						if (data != null) {
							initd.dg.datagrid('reload');
							$.messager.alert('提示','密码修改成功！');
							console();
						}
					},
					error:function(err, status){
						errorMsgAlert(err);
					}
				});
			}
		}
		
		
		$.ajax({
		    type: "POST",
		    url: projectName+"/system/userinfo/current",
		    dataType: "json",
		    success: function(data){
                var loginUser = data.entity;
                loginName = loginUser.loginName;
		    	document.getElementById("td_loginName").innerHTML =  '当前用户：'+loginUser.loginName;
				document.getElementById("td_userName").innerHTML =  '['+loginUser.userName+']';
		    }
		});

	</script>
</body>
</html>

